package main.Game;

import java.io.IOException;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import main.BaseServlet;
import main.PMF;
import main.UserView;

import DBClasses.Game;
import DBClasses.User;

@SuppressWarnings("serial")
public class DeleteGame extends BaseServlet
{
	@SuppressWarnings({ "unchecked" })
	@Override
	protected void action(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException
	{
		UserView uv = (UserView) req.getSession().getAttribute("user");
		User usr = null;
		if (uv != null)
			usr = uv.getUser();
		if (usr != null && usr.haveShopAccess())
		{
			PersistenceManager manager = PMF.get().getPersistenceManager();
			List<Game> ns = (List<Game>) manager.newQuery(
					"select from " + Game.class.getName() + " where id == "
							+ req.getParameter("id").toString()).execute();
			if (ns != null && ns.size() > 0)
				manager.deletePersistent(ns.get(0));
			manager.close();
		}
	}
}
